{oapdf_gg}
Office software is closely linked to the PDF,the PDF is also must have to control!      Set home Page  Add to Favorites  
You are here:Home > PDF Application > PDF Development
PDF Development
In the JSP use iText to generate PDF reports
Finishing by: Date:2009-04-17 21:05:08 Popularity: Tags:

recently made a statement through the JSP to generate PDF of small projects, can be regarded as an open field of vision. Some of the information through the enterprise network formation Html statements, although IE can show up in either print the contents, but from the interface point of view, if the display directly to the Html print out the results, it is not beautiful. If it is converted into PDF file and then print, then print the outcome will be a lot better.

iText Introduction

iText is an open-source Java class library that can be used to easily generate PDF files. You by visiting http://sourceforge.net/project/showfiles.php?group_id=15255&release_id = 167948 to download the latest version of the library, after the download is complete will be one. jar package, this package by adding the classpath to use JDK. If the generated PDF documents that need to appear in Chinese, Japanese, Korean characters, are also needed to visit http://itext. sourceforge.net/ downloads/ iTextAsian.jar download iTextAsian.jar package.

on the use of iText library, http://www.lowagie.com/iText/tutorial/index. html a more detailed tutorial. Getting Started tutorial from the start systematically introduced in the PDF file Add text, pictures, forms, etc. The methods and techniques. After reading this tutorial, you can do something more or less from the simple to the complex PDF files. However, attempts to resolve the tutorial to generate PDF documents in the course of all the difficulties is an extravagant hope. So, read the api documentation iText is very important. Download class library readers at the same time, you can download the document library.

in java how to use iText to generate PDF reports process

The following is a tutorial in the above-mentioned one of the most simple example, this example depicts a iText to generate PDF files through the normal procedure for the framework. Readers only need to document.open (); and document.close (); the middle of the two statements they want to join in on the contents of PDF documents can be. The only example of the addition of PDF file "Hello World" line of text.


Document document = new Document ();

try

(

PdfWriter.getInstance (document, new FileOutputStream ( "Chap0101.pdf "));

document.open ();

document.add (new Paragraph ( "Hello World "));

)

catch (DocumentException de)

(

System.err.println (de.getMessage ());

)

catch (IOException ioe)

(

System.err.println (ioe.getMessage ());

)

document.close ();

can be seen from the above example, the program's framework is very clear. However, in the PDF specified in the text, pictures, forms the location is a very troublesome thing. In addition to continually modify the location in the procedure, and then run the program, to generate PDF documents, observation of elements in the PDF in the location of such a process is reasonable, the other appears to be no better way.

in this part of the iText tutorial does not have an Internet-related information is also relatively small. I have seen in CSDN asked to achieve was to open with the details, it was back to achieve the principle: first on the server to generate PDF documents, and then point to the user by clicking the hyperlink PDF files download or open choice. This is an idea, or one train of thought. In this paper, the realization of this idea, and another line of thought is given through the realization of two ways.

1) directly on the server to generate PDF files.

<% @ page import = "com.lowagie.text .*, com.lowagie.text.pdf .*, java.io. *"%>

<%

String filename = "PDF" + (new Random ()). nextInt ()+". pdf ";

Document document = new Document (PageSize.A4);

ServletOutputStream out1 = response.getOutputStream ();

try

(

PdfWriter writer = PdfWriter.getInstance (document, new FileOutputStream (filename));

document.open ();

document.add (new Paragraph ( "Hello World "));

document.close ();

)

catch (Exception e ){}%>

above procedure on the server to generate a static PDF document. Clearly, each running from the PDF file's name should be unique there can be heavy. This procedure generates a random function to rename the PDF file. Shortcomings of this procedure is that each run on the server will generate a PDF file, if not promptly removed, the number of growing sites is obviously defenders do not want to see.

there isArticle InformationsComment Information
Category column

Site Help | Site Map | Feedback |
OAPDF.COM Copyright 2009 V1.1